/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: Wangyaoxi
 * Date: 2010-4-13 下午12:43:28
 */
package com.ccxe.manage.service.transaction;

import java.sql.ResultSet;

import com.ccxe.manage.db.CcxDB;
import com.ccxe.manage.db.DBFactory;

/**
 * 数据库事务类
 * 
 * @author wyx
 * 
 */
public class TransactionCcxDb {

	private CcxDB db;

	/**
	 * 开始事务
	 */
	public void beginTransaction() {
		try {
			db = DBFactory.getInstance();
			db.setAutoCommit(false);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查询
	 * 
	 * @param sqlString
	 * @return
	 * @throws Exception
	 */
	public ResultSet executeQuery(String sqlString) throws Exception {
		ResultSet result = db.executeQuery(sqlString);
		return result;
	}

	/**
	 * 查询
	 * 
	 * @param sqlString
	 * @return
	 * @throws Exception
	 */
	public ResultSet executeQuery(String preString, Object[] values)
			throws Exception {
		ResultSet result = db.executeQuery(preString, values);
		return result;
	}

	/**
	 * 其他操作
	 * 
	 * @param sqlString
	 * @param value
	 * @return
	 * @throws Exception
	 */
	public int executeUpdate(String preString, Object[] value) throws Exception {
		int result = db.executeUpdate(preString, value);
		return result;
	}

	// 提交
	public void commit() throws Exception {
		db.commit();
	}

	// 回滚
	public void rollback() throws Exception {
		db.rollback();
	}

	// 关闭
	public void close() throws Exception {
		if (db != null) {
			db.close();
		}
	}
}
